package com.ruoyi.web.controller.common;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.controller.util.OssUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/system/file")
public class FileController {

    private String bucket = "hygascontrol";
    private String preUrl = "http://hygascontrol.oss-cn-shanghai.aliyuncs.com";
    //@ApiOperation(value = "上传单个文件")
    @PostMapping("/singleFile")
    public AjaxResult uploadFile(MultipartFile file) {
        Integer user_id = 1;
        Long userId = user_id.longValue();
        String gicon = OssUtil.uploadFile(file,userId,bucket);
        String url = preUrl+'/'+gicon;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("url", url);
        return ajax;
    }

    // @ApiOperation(value = "上传多个文件")
    @PostMapping("/multipartFiles")
    @ResponseBody
    public AjaxResult uploadFiles(
            @RequestParam MultipartFile[] IMG_gicons) {
        String gimg = OssUtil.getIMGS(IMG_gicons, 55555L, bucket);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("gimg", gimg);
        return ajax;
    }


}